import React, { PureComponent } from 'react'
import { Avatar, Button, List } from 'antd-mobile'
import Header from '../../components/Header/Header'
import { $pre } from '../../http/http'

export class Mine extends PureComponent {
  constructor(){
    super()
    this.state = {
      user:{
        name:"",
        img:"",
        description:"这个人很懒什么也没留下"
      }
      
    }
  }
  componentDidMount(){
    this.getUserInfo()
  }
  async getUserInfo(){
    this.setState({
      user:{
        ...this.state.user,
        name:JSON.parse(sessionStorage.getItem("isLogin")).nickname
      }
    })
  }
  render() {
    let {name,img,description} = this.state.user
    return (
      <div>
        <Header title="我的" back></Header>
        <List>
          <List.Item
            prefix={<Avatar src={$pre+img} />}
            description={description}>
            {name}
          </List.Item>
        </List>
        <Button block color='danger' onClick={()=>{
          sessionStorage.removeItem("isLogin")
          this.props.history.replace("/")
        }}>退出登录</Button>
      </div>
    )
  }
}

export default Mine